<?php
	session_start();
	/**
	* @package admin
	* @desc Page for displaying the user details.
	*/
	
	if ($_SESSION["role"] != "admin")
	{
		header('Location: ../index.php');
		exit();
	}
	
	// Direct calling check
	if(!isset($_GET['id']))
	{
		header('Location: finduser.php');
		exit();
	}
	
	/**
	* @desc This include file will load the directory settings for the Smarty Templates
	*/
	require '../includes/smarty.inc';
	$smarty->assign('title', "Add Park");
	$smarty->assign('user_id', $_SESSION["user_id"]);	
	$smarty->assign('last', $_SESSION["lastviewed"]);
	$smarty->assign('firstname', $_SESSION["firstname"]);
	$smarty->assign('role', $_SESSION["role"]);
	$smarty->assign('top5', $_SESSION["top5"]);	
	$smarty->assign('pathdepth', "../");
	$smarty->display('header.tpl');
	
	
	
	//get user id
	$user_id = $_GET['id'];
	
	/**
	* @desc This include file connects to the database.
	*/
	require '../includes/connect.inc';
	
	//prepare query
	$user_query = "SELECT user_id, firstname, lastname, email, role FROM users WHERE user_id = $user_id";
	
	//run query
	$result = mysql_query($user_query, $connection) or die("Could not load user details. Try again later.");
	
	
	$name = $_SESSION['userresults']['name'];
	$email = $_SESSION['userresults']['email'];
	$role = $_SESSION['userresults']['role'];
	
	$smarty->assign('name', $name);	
	$smarty->assign('email', $email);	
	$smarty->assign('role', $role);	
	
	if(mysql_num_rows($result) > 0)
	{
		$row = mysql_fetch_array($result);
		
		$smarty->assign('user_id', $row['user_id']);	
		$smarty->assign('user_firstname', $row['firstname']);	
		$smarty->assign('user_lastname', $row['lastname']);	
		$smarty->assign('user_email', $row['email']);	
		$smarty->assign('user_role', $row['role']);	
		$success = true;
		$smarty->assign('success', $success);
	}	
	else
	{
		$fail = "Failed to load user info. Try again.";
		$smarty->assign('fail', $fail);
	}
	$smarty->display('admin/userdetail.tpl');
	
	// Disconnect
	mysql_close($connection);
	
	
		
	$smarty->assign('pathdepth', "../");
	$smarty->display('footer.tpl');
	
?>